废话不多说了,c语言大作业代码 + 1

2019河北省赛的D题,榜单的简易版

23333我不会告诉你们盟盟的题册是我给的hhh

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
#include <stdio.h>
#include <string.h>
#define minn(a,b) a > b ? a : b ;

struct Student
{
char name[50];
int solve ;
int pro[20] ;
int pass[20] ;
int ifdo[20] ;
bool sub ;
bool vis ;
}team[5005],temp;

int bianli(char *m, int n)
{
int i;
for(i = 1; i <= n; ++ i)
{
if(strcmp(team[i].name,m) == 0 )
return i ;
}
return 0 ;
}

int Penalty(Student a,int n)
{
int i ;
int sum = 0 ;
for(i = 1; i < n + 1 ; ++ i )
{
if(a.ifdo[i] != 0 && a.pass[i] >= 0 )
sum += a.pro[i];
}
return sum ;
}

int Same(Student a , Student b , int n)
{
if(Penalty(a,n) == Penalty(b,n) && a.solve == b.solve)
return 1 ;
else
return 0 ;
}

void Print(Student *team , int n , int near , int cnt )
{
int i , k ;
printf("Rank Who Solved Penalty");
for(i = 0 ; i < n ; ++ i)
printf(" %c",i + 'A') ;
printf("\n") ;
for(i = 1; i < cnt + 1 ; ++ i)
{
if(team[i].vis == 0)
break ;
else
{
if(Same(team[i],team[i - 1],n))
printf("%4d",near);
else
{
near = i ;
printf("%4d",i) ;
}
}
printf(" %43s",team[i].name) ;
printf(" %6d",team[i].solve) ;
printf(" %7d",Penalty(team[i],n)) ;
for(k = 1 ; k < n + 1 ; ++ k)
{
if(team[i].ifdo[k] == 0)
printf(" ");
else
{
if(team[i].pass[k] > 0)
printf(" +%d",team[i].pass[k]) ;
if(team[i].pass[k] < 0)
printf(" %d",team[i].pass[k]) ;
if(team[i].pass[k] == 0)
printf(" +") ;
}
}
printf("\n") ;
}
}

void Sort(Student *team , int cnt , int n)
{
int i , j ;
for(i = 1 ; i < cnt + 1; ++ i)
{
for(j = 1 ; j < cnt - i + 1 ; ++ j)
{
if(team[j].solve < team[j + 1].solve)
{
temp = team[j] ;
team[j] = team[j + 1] ;
team[j + 1] = temp ;
}
if(team[j].solve == team[j + 1].solve )
{
if(Penalty(team[j],n) > Penalty(team[j + 1],n))
{
temp = team[j] ;
team[j] = team[j + 1] ;
team[j + 1] = temp ;
}
if(Penalty(team[j],n) == Penalty(team[j + 1],n))
{
if(strcmp(team[j].name,team[j + 1].name) > 0 )
{
temp = team[j] ;
team[j] = team[j + 1] ;
team[j + 1] = temp ;
}
}
}
}
}
}

int main(void)
{
int n, cnt, flag, near, t, num, i, j,nextpos;
int zhuang[10] ;
char m[205], nowteam[50];
char zhuangtai[10][30] = {"Accepted ","Wrong Answer ","Time Limit Exceeded ", "Compile Error ", "Memory Limit Exceeded ", "Output Limit Exceeded ", "Runtime Error ", "Presentation Error "} ;
Student temp ;
scanf("%d",&n) ;
getchar() ;
cnt = 0 ;
near = -1 ;
while(gets(m) && m[0] != 'G')
{
t = ((m[0] - '0') * 10 + (m[1] - '0')) * 60 + (m[3] - '0') * 10 + (m[4] - '0');
num = m[6] - 'A' + 1;
memset(zhuang , 0 , sizeof (zhuang)) ;
for(i = 0 ; i < 8 ; ++ i)
zhuang[i] = strlen(zhuangtai[i]) ;
if (m[8] == 'A')
nextpos = 8 + zhuang[0] ;
if (m[8] == 'W')
nextpos = 8 + zhuang[1] ;
if (m[8] == 'T')
nextpos = 8 + zhuang[2] ;
if (m[8] == 'C')
continue;
if (m[8] == 'M')
nextpos = 8 + zhuang[4] ;
if (m[8] == 'O')
nextpos = 8 + zhuang[5] ;
if (m[8] == 'R')
nextpos = 8 + zhuang[6] ;
if (m[8] == 'P')
nextpos = 8 + zhuang[7] ;
strcpy(nowteam , m + nextpos);
flag = bianli(nowteam,cnt);
if(flag == 0 )
{
flag = ++ cnt;
team[flag].sub = 1;
strcpy(team[flag].name , nowteam) ;
if(m[8] == 'A')
{
team[flag].pro[num] += t ;
team[flag].pass[num] = 0 ;
team[flag].solve += 1 ;
}
else
{
team[flag].pro[num] += 20 ;
team[flag].pass[num] -= 1 ;
}
}
else
{
if(team[flag].pass[num] > 0)
break ;
if(m[8] == 'A')
{
team[flag].pro[num] += t ;
team[flag].pass[num] *= -1 ;
team[flag].solve += 1 ;
}
else
{
team[flag].pro[num] += 20 ;
team[flag].pass[num] -= 1 ;
}
}
team[flag].ifdo[num] = 1 ;
team[flag].vis = 1 ;
}
Sort(team , cnt ,n) ;
Print(team , n , near , cnt) ;
return 0 ;
}
------------这篇文章结束了呢要不要夸夸我呢-------------